//
//  XJVisitorController.swift
//  新浪微博
//
//  Created by 徐绩 on 16/4/16.
//  Copyright © 2016年 ayumi. All rights reserved.
//

import UIKit

class XJVisitorController: UITableViewController,XJVisitorViewDelegate {
    
    //用户是否登录
    var userLogon: Bool = XJUserAccountModel.sharedModel.islogin
    
    /**
     根据用户是否登录判断是否加载访客视图
     */
    override func loadView() {
        
        userLogon ? super.loadView() : setupVisitorView()        
    }
    
    /**
     设置VisitorView
     */
    private func setupVisitorView(){
    
        view = visitorView
        //设置左右两个item
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "didClickRegistBtn");
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "didClickLoginBtn")
        
    }

     /// 懒加载控件
    lazy var visitorView: XJVisitorView = {
    
        let visitorView = XJVisitorView()
        visitorView.delegate = self
        
        return visitorView
    }()
    
    /**
     实现代理方法
     */
    func didClickLoginBtn(){
        
        presentViewController(UINavigationController (rootViewController: XJOAuthController()), animated: true, completion: nil)
    }
    
    func didClickRegistBtn(){
    
        presentViewController(UINavigationController (rootViewController: XJOAuthController()), animated: true, completion: nil)
    }
}
